package com.example.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class TimeAspect {
    @Pointcut("execution(* com.example.service..*.select*(..))")
    public void pt() {
    }

    @Around("pt()")
    public Object around(ProceedingJoinPoint pjp) {
        Object result = null;
        try {
            Long startTime = System.currentTimeMillis();
            result = pjp.proceed();
            Long endTime = System.currentTimeMillis();
            System.err.println(pjp.getSignature().getName()+"运行耗时"+(endTime-startTime)+"毫秒");
//            System.err.println(endTime - startTime);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return result;

    }
}
